package request_self

import (
	//https://blog.csdn.net/gitblog_00573/article/details/142837577
	"github.com/asmcos/requests"
)

// Requests 个人请求
// :Params 用于get传参 请求使用
// :Payload 用于post传参 请求使用
// :Files 用于发送文件 请求使用
type Requests struct {
	Header  requests.Header
	Url     string
	Params  requests.Params
	Payload requests.Datas
	Files   requests.Files
}

func (r *Requests) GetRequest() requests.Response {
	response, er := requests.Get(r.Url, r.Header, r.Params)
	if er != nil {
		println(r.Url, r.Payload, er)
		panic(er)
	}

	return *response
}

func (r *Requests) PostRequest() requests.Response {
	response, er := requests.Post(r.Url, r.Header, r.Payload)
	if er != nil {
		println(r.Url, r.Payload, er)
		panic(er)
	}

	return *response
}

// demo
func main() {
	header := map[string]string{
		"test": "1",
	}
	url := "https://www.baidu.com"
	payload := map[string]string{
		"test": "1",
	}
	requests_self := Requests{
		Header:  header,
		Url:     url,
		Payload: payload,
	}

	response := requests_self.GetRequest()
	println(response.Text())
}
